using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;

namespace Wpf_Scrcpy.MOD
{
    /// <summary>
    /// 应用程序信息类
    /// </summary>
    public class AppInfo
    {
        /// <summary>
        /// 应用包名
        /// </summary>
        public string PackageName { get; set; }

        /// <summary>
        /// 应用显示名称
        /// </summary>
        public string DisplayName { get; set; }

        /// <summary>
        /// 应用标签（通常是应用名称）
        /// </summary>
        public string Label { get; set; }

        /// <summary>
        /// 是否为系统应用
        /// </summary>
        public bool IsSystemApp { get; set; }

        /// <summary>
        /// 应用图标（Base64编码的PNG图片）
        /// </summary>
        public string IconBase64 { get; set; }

        /// <summary>
        /// 应用图标的BitmapImage对象
        /// </summary>
        public BitmapImage IconImage { get; set; }

        /// <summary>
        /// 应用版本名称
        /// </summary>
        public string VersionName { get; set; }

        /// <summary>
        /// 应用版本代码
        /// </summary>
        public string VersionCode { get; set; }

        /// <summary>
        /// 显示文本（用于ComboBox显示）
        /// </summary>
        public string DisplayText => string.IsNullOrEmpty(Label) ? PackageName : $"{Label} ({PackageName})";

        /// <summary>
        /// 简短显示文本（不含包名）
        /// </summary>
        public string ShortDisplayText => string.IsNullOrEmpty(Label) ? PackageName : Label;

        /// <summary>
        /// 获取应用图标emoji
        /// </summary>
        public string AppIcon => GetAppIconEmoji();

        /// <summary>
        /// 根据包名获取相应的图标emoji
        /// </summary>
        private string GetAppIconEmoji()
        {
            if (string.IsNullOrEmpty(PackageName))
                return "📱";

            var package = PackageName.ToLower();

            // 系统应用图标
            if (package.Contains("settings")) return "⚙️";
            if (package.Contains("camera")) return "📷";
            if (package.Contains("gallery") || package.Contains("photos")) return "🖼️";
            if (package.Contains("music") || package.Contains("audio")) return "🎵";
            if (package.Contains("calculator")) return "🔢";
            if (package.Contains("contacts")) return "👥";
            if (package.Contains("dialer") || package.Contains("phone")) return "📞";
            if (package.Contains("mms") || package.Contains("message")) return "💬";
            if (package.Contains("email") || package.Contains("gmail")) return "📧";
            if (package.Contains("calendar")) return "📅";
            if (package.Contains("browser") || package.Contains("chrome")) return "🌐";
            if (package.Contains("clock") || package.Contains("alarm")) return "⏰";
            if (package.Contains("file") || package.Contains("manager")) return "📁";

            // 社交应用图标
            if (package.Contains("tencent.mm")) return "💬"; // 微信
            if (package.Contains("tencent.mobileqq")) return "🐧"; // QQ
            if (package.Contains("sina.weibo")) return "📢"; // 微博
            if (package.Contains("facebook")) return "📘";
            if (package.Contains("twitter")) return "🐦";
            if (package.Contains("instagram")) return "📸";
            if (package.Contains("whatsapp")) return "💬";
            if (package.Contains("telegram")) return "✈️";
            if (package.Contains("linkedin")) return "💼";
            if (package.Contains("discord")) return "🎮";

            // 娱乐应用图标
            if (package.Contains("youtube")) return "📺";
            if (package.Contains("netflix")) return "🎬";
            if (package.Contains("spotify")) return "🎵";
            if (package.Contains("douyin") || package.Contains("tiktok")) return "🎵"; // 抖音
            if (package.Contains("kuaishou")) return "⚡"; // 快手
            if (package.Contains("iqiyi")) return "🎭"; // 爱奇艺
            if (package.Contains("youku")) return "📹"; // 优酷
            if (package.Contains("bilibili")) return "📺";
            if (package.Contains("douyu")) return "🎮"; // 斗鱼
            if (package.Contains("vlc")) return "🎬";

            // 购物应用图标
            if (package.Contains("taobao")) return "🛒"; // 淘宝
            if (package.Contains("tmall")) return "🏪"; // 天猫
            if (package.Contains("jingdong") || package.Contains("jd")) return "📦"; // 京东
            if (package.Contains("amazon")) return "📦";
            if (package.Contains("ebay")) return "🛒";

            // 出行应用图标
            if (package.Contains("didi")) return "🚗"; // 滴滴
            if (package.Contains("baidu") && package.Contains("map")) return "🗺️"; // 百度地图
            if (package.Contains("autonavi")) return "🧭"; // 高德地图
            if (package.Contains("maps")) return "🗺️";
            if (package.Contains("uber")) return "🚗";

            // 音乐应用图标
            if (package.Contains("netease") && package.Contains("cloudmusic")) return "☁️"; // 网易云音乐
            if (package.Contains("kugou")) return "🎶"; // 酷狗音乐
            if (package.Contains("kuwo")) return "🎶"; // 酷我音乐
            if (package.Contains("qqmusic")) return "🎵"; // QQ音乐

            // 金融应用图标
            if (package.Contains("alipay")) return "💰"; // 支付宝
            if (package.Contains("bank")) return "🏦";
            if (package.Contains("payment") || package.Contains("pay")) return "💳";

            // 工具应用图标
            if (package.Contains("office")) return "📄";
            if (package.Contains("wps")) return "📝";
            if (package.Contains("adobe")) return "🎨";
            if (package.Contains("zoom")) return "📹";
            if (package.Contains("skype")) return "📞";

            // 游戏应用图标
            if (package.Contains("game") || package.Contains("play")) return "🎮";
            if (package.Contains("tencent") && (package.Contains("tmgp") || package.Contains("game"))) return "🎮";
            if (package.Contains("minecraft")) return "🧱";
            if (package.Contains("pokemon")) return "⚡";

            // 新闻应用图标
            if (package.Contains("news") || package.Contains("xinwen")) return "📰";
            if (package.Contains("toutiao")) return "📰"; // 今日头条

            // 健康应用图标
            if (package.Contains("health") || package.Contains("fitness")) return "💪";
            if (package.Contains("step") || package.Contains("sport")) return "🏃";

            // 教育应用图标
            if (package.Contains("education") || package.Contains("learn")) return "📚";
            if (package.Contains("duolingo")) return "🦉";

            // 默认图标
            if (IsSystemApp) return "⚙️";
            return "📱";
        }

        public override string ToString()
        {
            return DisplayText;
        }
    }
}
